/*首页对象*/
var Index = {
};




var setting = {
	view: {
		showIcon: false,
		selectedMulti: false
	},
	data: {
		simpleData: {
			enable: true
		}
	},
	callback: {
		beforeClick: beforeClick,
		onClick: onClick
	}
};

var log, className = "dark";

function beforeClick(treeId, treeNode, clickFlag) {
	showLog(treeNode.level);
	if(treeNode.level==0){
		return false
	}else{
		return true;
	}
}
function onClick(event, treeId, treeNode, clickFlag) {
	showLog("[ "+getTime()+" onClick ]&nbsp;&nbsp;clickFlag = " + clickFlag + " (" + (clickFlag===1 ? "普通选中": (clickFlag===0 ? "<b>取消选中</b>" : "<b>追加选中</b>")) + ")");
	showLog(treeNode);
	$("#selectArea").html(treeNode.name);
	if(treeNode.level==1){
		window.location.href=Feng.ctxPath+"/screening?areaId="+treeNode.id+"&areaName="+treeNode.name;
	}else if(treeNode.level==2){
		var parentNode=treeNode.getParentNode();
		window.location.href=Feng.ctxPath+"/screening?areaId="+parentNode.id+"&subAreaId="+treeNode.id+"&areaName="+treeNode.name;
	}
	//TODO 根据areaId跳转到景区监控
}

function showLog(str) {
	console.log(str);
}
function getTime() {
	var now= new Date(),
	h=now.getHours(),
	m=now.getMinutes(),
	s=now.getSeconds();
	return (h+":"+m+":"+s);
}

function showIconForTree(treeId, treeNode) {
	return !treeNode.isParent;
};

function refresh()
{
	window.location.reload();
	console.log("===============定时刷新============");
}

var ztree ;
$(function () {
	//初始化区域树
	//$.fn.zTree.init($("#areaTree"), setting, zNodes);
	
	ztree = new $ZTree("areaTree", "/screening/tree");
	ztree.setSettings(setting);
    //ztree.bindOnClick(MgrUser.onClickDept);
    ztree.init();
	

	$(".dropdown-menu").on('click', function (e) {
        e.stopPropagation();
    });
	$('[data-toggle="popover"]').popover();
	
	
	//根据告警级别，给不同的级别配置不同的css类
	$("[name='warnLevel']").each(function(){
		if($(this).text()=="正常"){
			$(this).css("color","#6699FF");
		}
		if($(this).text()=="告警"){
			$(this).css("color","#FF9900");
		}
		if($(this).text()=="饱和"){
			$(this).css("color","#FF3300");
		}
		if($(this).text()=="严重"){
			$(this).css("color","#CC0000");
		}
	});
	
	setInterval("refresh()",3600000);
	
});
